<template>
  <el-dialog v-if="visible" :title="info.title" :visible.sync="visible" append-to-body center width="560px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="120px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="待办事项">
            {{ form.name }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="附件上传" prop="files">
            <Upload v-model="form.files" />
          </el-form-item>
        </el-col>
        <el-col v-if="fileList.length > 0" :span="24" class="mb20">
          <el-form-item label="附件">
            <el-table class="search-table" :data="fileList" border fit highlight-current-row style="width: 100%;">
              <el-table-column label="序号" align="center" width="56px">
                <template slot-scope="{$index}">
                  {{ $index + 1 }}
                </template>
              </el-table-column>
              <el-table-column label="文件名称" min-width="200px">
                <template slot-scope="{row}">
                  <a href="javascript:void(0)" class="tba" target="_blank" @click="handleWV(row.url)">{{ row.file_name }}</a>
                </template>
              </el-table-column>
              <el-table-column label="下载" align="center" width="90px">
                <template slot-scope="{row}">
                  <a :href="row.url" class="tba" target="_blank">下 载</a>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" :rows="4" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button v-if="info.type !== 'view'" type="primary" size="small" @click="handleEdit()">提 交</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import Upload from '@/myComponents/Upload'
import { updAgentMatter, myAgentMatter } from '@/api/agent/agent'
import { allFiles } from '@/api/file'
import form from '@/utils/form'

export default {
  components: { Upload },
  extends: form,
  props: {
    reqAdd: {
      default: updAgentMatter,
      type: Function
    }
  },
  data() {
    return {
      fileList: [],
      rules: {
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.$set(this, 'form', this.info.edit)
        this.handleMyAgentMatter()
        this.handleFiles()
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    handleMyAgentMatter() {
      myAgentMatter({ id: this.form.id }).then(res => {
        this.form = res.bean
      }).catch(err => {
        this.$message.error(err.msg || '请求失败')
      })
    },
    handleFiles() {
      allFiles({
        db_type: 'logc_agent_matter_archives',
        e_ids: this.form.id
      }).then(response => {
        this.fileList = response.list
      }).catch(err => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>

<style scoped>
</style>
